#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:FileName: base.py
:Project:
:Brand:
:Version:
:Description: 
:Author: He YinYu
:Link:
:Time: 2025/5/6 11:38
"""
from tortoise.models import Model
from tortoise import fields
from tortoise.contrib.pydantic import pydantic_model_creator


class BaseModel(Model):
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")

    async def to_dict(self):
        cls_pydantic = pydantic_model_creator(self.__class__)
        slf = await cls_pydantic.from_tortoise_orm(self)

        return slf.model_dump(mode="json")

    class Meta:
        abstract = True
